//150. 逆波兰表达式求值

#include <string>
#include <vector>
#include <stack>
using namespace std;

class Solution{
public:
    int evalRPN(vector<string>& tokens) {
        stack<int> st;
        for(auto& s : tokens)
        {
            if(s == "+"
            || s == "-"
            || s == "*"
            || s == "/")
            {
                int right = st.top();
                st.pop();
                int left = st.top();
                st.pop();
                
                switch(s[0])
                {
                case '+':
                    st.push(left+right);
                    break;
                case '-':
                    st.push(left-right);
                    break;
                case '*':
                    st.push(left*right);
                    break;
                case '/':
                    st.push(left/right);
                    break;
                }
            }
            else
            {
                st.push(stoi(s));
            }
        }
        return st.top();
    }
};